//@version=4
// name:        Delorean TDI - Traders Dynamic Index
// credit:      Modified version of [Indicators: Traders Dynamic Index, HLCTrends and Trix Ribbon] by LazyBear
// author:      eldindidic
// published:   10/23/20
// updated:     04/16/22
// version:     0.4.1.1

study("Delorean TDI - Traders Dynamic Index", shorttitle="Delorean TDI", overlay = false)

rsiPeriod = input(21, minval = 1, title = "RSI Period")
lengthRsi = input(34, minval = 1, title = "Band Length")
lengthRsiSlow = input(7, minval = 0, title = "Slow MA on RSI")
lengthRsiFast = input(2, minval = 1, title = "Fast MA on RSI")

src = close                                                         // Source of Calculations (Close of Bar)
r = rsi(src, rsiPeriod)                                             // RSI of Close
ma = sma(r, lengthRsi)                                              // Moving Average of RSI [current]
offs = (1.6185 * stdev(r, lengthRsi))                               // Offset
up = ma + offs                                                      // Upper Bands
dn = ma - offs                                                      // Lower Bands
mid = (up + dn) / 2                                                 // Average of Upper and Lower Bands
slowMA = sma(r, lengthRsiSlow)                                      // Moving Average of RSI 7 bars back
fastMA = sma(r, lengthRsiFast)                                      // Moving Average of RSI 2 bars back

hline(20, title = "Extremely Oversold", color = #5d606b )           // Extremely Oversold
hline(30, title = "Highly Oversold", color = #787b86 )              // Highly Oversold
hline(40, title = "Oversold", color = #b2b5be )                     // Oversold
hline(50, title = "Midline", color = #d1d4dc )                      // Midline
hline(60, title = "Overbought", color = #b2b5be )                   // Overbought
hline(70, title = "Highly Overbought", color = #787b86 )            // Highly Overbought
hline(80, title = "Extremely Overbought", color = #5d606b )         // Extremely Overbought

plot(up, title = "Upper Band", color = #1976d2, linewidth = 2)      // Upper Band
plot(dn, title = "Lower Band", color = #1976d2, linewidth = 2)      // Lower Band
plot(mid, title = "Middle Band", color = #fbc02d, linewidth = 2)    // Middle Band
plot(slowMA, title = "Slow MA", color = #b71c1c, linewidth = 2)     // Slow Moving Average
plot(fastMA, title = "Fast MA", color = #388e3c, linewidth = 2)     // Fast Moving Average